<template>
  <el-container class="cf">
    <el-main class="lh300 cf ">
      <el-row :gutter="10" type="flex" justify="center">
        <el-col :span="8">
          职位:<el-select v-model="position" filterable placeholder="请选择职位">
          <el-option
            v-for="item in position_list"
            :key="item.id"
            :label="item.title"
            :value="item.id + '|' + item.title">
          </el-option>
        </el-select>

        </el-col>
        <el-col :span="8">
          部门:<el-select v-model="dept" filterable placeholder="请选择部门">
            <el-option
              v-for="item in dept_list"
              :key="item.id"
              :label="item.title"
              :value="item.id + '|' + item.title">
            </el-option>
          </el-select>
        </el-col>

        <el-col :span="8"><el-button type="primary" @click="change_position">确定</el-button></el-col>
      </el-row>
    </el-main>
  </el-container>
</template>

<script>

import {getUserPosition} from '@/apilist/login'

    export default {
        name: "change_position",
      data(){
          return {
           position_list:[],
            dept_list:[],
            dept:'',
            position:'',
            uid:'',
          };
      },
      methods: {
        change_position() {
          let _this = this;
          if (_this.fun.isNull(_this.dept) || _this.fun.isNull(_this.position)) {
            _this.$message.error('请选择职位或者部门');
            return;
          }

          let userinfo = sessionStorage.getItem('userinfo')

          userinfo = JSON.parse(userinfo)

          let dept_arr = this.dept.split('|')

          let position_arr = this.position.split('|')

          userinfo.dept_id = dept_arr[0]
          userinfo.dept_name = dept_arr[1]

          userinfo.position_id = position_arr[0]
          userinfo.position_name = position_arr[1]


          sessionStorage.setItem('userinfo', JSON.stringify(userinfo));
          _this.$router.push('/home');
        },
      },

      mounted() {
          let userinfo = sessionStorage.getItem('userinfo');
           userinfo = JSON.parse(userinfo)
           this.uid = userinfo.uid
           let query = {id:this.uid}
           getUserPosition(query).then(res => {
             this.position_list = res.data.position_list;
             this.dept_list = res.data.dept_list;
           })

      }
    }
</script>

<style scoped>
  @import '../../../static/css/chang_position.css';
</style>
